package com.gitee.helioz.openai.api.endpoint.edits;

import com.gitee.helioz.openai.api.OpenAiService;
import com.gitee.helioz.openai.api.dto.edits.EditRequest;
import com.gitee.helioz.openai.api.dto.edits.EditResponse;
import com.gitee.helioz.openai.common.constants.OpenAiApiUrl;
import com.gitee.helioz.openai.common.util.json.GsonUtil;
import lombok.RequiredArgsConstructor;

/**
 * 〈文本编辑服务〉
 *
 * @author <a href="https://gitee.com/helioz">Morning Starr</a>
 */
@RequiredArgsConstructor
public class EditServiceImpl implements EditService {

    private final OpenAiService openAiService;

    @Override
    public EditResponse create(EditRequest editRequest) {
        String requestJson = GsonUtil.toJson(editRequest);
        String responseStr = openAiService.post(OpenAiApiUrl.Edits.CREATE_EDIT.getUrl(openAiService.getApiHost()), requestJson);
        return GsonUtil.fromJson(responseStr, EditResponse.class);
    }

}
